home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / mule / mule-cmds.el.z / mule-cmds.el
Encoding:
Text File  |  1998-05-21  |  27.5 KB  |  712 lines

  1. ;;; mule-cmds.el --- Commands for multilingual environment
  2.  
  3. ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
  4. ;; Licensed to the Free Software Foundation.
  5. ;; Copyright (C) 1997 MORIOKA Tomohiko
  6.  
  7. ;; Keywords: mule, multilingual
  8.  
  9. ;; This file is part of XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  23. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. ;; 02111-1307, USA.
  25.  
  26. ;;; Code:
  27.  
  28. ;;; MULE related key bindings and menus.
  29.  
  30. (defvar mule-keymap (make-sparse-keymap "MULE")
  31.   "Keymap for MULE (Multilingual environment) specific commands.")
  32.  
  33. ;; Keep "C-x C-m ..." for mule specific commands.
  34. (define-key ctl-x-map "\C-m" mule-keymap)
  35.  
  36. (define-key mule-keymap "f" 'set-buffer-file-coding-system)
  37. (define-key mule-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs
  38. (define-key mule-keymap "t" 'set-terminal-coding-system)
  39. (define-key mule-keymap "k" 'set-keyboard-coding-system)
  40. (define-key mule-keymap "p" 'set-buffer-process-coding-system)
  41. (define-key mule-keymap "\C-\\" 'select-input-method)
  42. (define-key mule-keymap "c" 'universal-coding-system-argument)
  43. ;;(define-key mule-keymap "c" 'list-coding-system-briefly) ; XEmacs
  44. (define-key mule-keymap "C" 'list-coding-system)     ; XEmacs
  45. (define-key mule-keymap "r" 'toggle-display-direction)     ; XEmacs
  46. (define-key mule-keymap "l" 'set-language-environment)
  47.  
  48. (define-key help-map "\C-L" 'describe-language-support)
  49. (define-key help-map "L" 'describe-language-environment)
  50. (define-key help-map "\C-\\" 'describe-input-method)
  51. (define-key help-map "I" 'describe-input-method)
  52. (define-key help-map "C" 'describe-coding-system)
  53. (define-key help-map "h" 'view-hello-file)
  54.  
  55. ;; Menu for XEmacs were moved to x11/x-menubar.el.
  56.  
  57.  
  58. ;; This should be a single character key binding because users use it
  59. ;; very frequently while editing multilingual text.  Now we can use
  60. ;; only two such keys: "\C-\\" and "\C-^", but the latter is not
  61. ;; convenient because it requires shifting on most keyboards.  An
  62. ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit'
  63. ;; but it won't be used that frequently.
  64. (define-key global-map "\C-\\" 'toggle-input-method)
  65.  
  66. (defun view-hello-file ()
  67.   "Display the HELLO file which list up many languages and characters."
  68.   (interactive)
  69.   ;; We have to decode the file in any environment.
  70.   (let ((coding-system-for-read 'iso-2022-7))
  71.     (find-file-read-only (expand-file-name "HELLO" data-directory))))
  72.  
  73. (defun universal-coding-system-argument ()
  74.   "Execute an I/O command using the specified coding system."
  75.   (interactive)
  76.   (let* ((coding-system
  77.       (read-coding-system "Coding system for following command: "))
  78.      (keyseq (read-key-sequence
  79.           (format "Command to execute with %s:" coding-system)))
  80.      (cmd (key-binding keyseq)))
  81.     (let ((coding-system-for-read coding-system)
  82.       (coding-system-for-write coding-system))
  83.       (message "")
  84.       (call-interactively cmd))))
  85.  
  86. (defun set-default-coding-systems (coding-system)
  87.   "Set default value of various coding systems to CODING-SYSTEM.
  88. The follwing coding systems are set:
  89.   o coding system of a newly created buffer
  90.   o default coding system for terminal output
  91.   o default coding system for keyboard input
  92.   o default coding system for subprocess I/O"
  93.   (check-coding-system coding-system)
  94.   ;;(setq-default buffer-file-coding-system coding-system)
  95.   (set-default-buffer-file-coding-system coding-system)
  96.   ;;(setq default-terminal-coding-system coding-system)
  97.   (setq terminal-coding-system coding-system)
  98.   ;;(setq default-keyboard-coding-system coding-system)
  99.   (setq keyboard-coding-system coding-system)
  100.   ;;(setq default-process-coding-system (cons coding-system coding-system))
  101.   (add-hook 'comint-exec-hook
  102.         `(lambda ()
  103.            (let ((proc (get-buffer-process (current-buffer))))
  104.          (set-process-input-coding-system  proc ',coding-system)
  105.          (set-process-output-coding-system proc ',coding-system)))
  106.         'append)
  107.   (setq file-name-coding-system coding-system))
  108.  
  109. (defun prefer-coding-system (coding-system)
  110.   "Add CODING-SYSTEM at the front of the priority list for automatic detection.
  111. This also sets the following coding systems to CODING-SYSTEM:
  112.   o coding system of a newly created buffer
  113.   o default coding system for terminal output
  114.   o default coding system for keyboard input
  115.   o default coding system for subprocess I/O"
  116.   (interactive "zPrefer coding system: ")
  117.   (if (not (and coding-system (coding-system-p coding-system)))
  118.       (error "Invalid coding system `%s'" coding-system))
  119.   (let ((coding-category (coding-system-category coding-system))
  120.     (parent (coding-system-parent coding-system)))
  121.     (if (not coding-category)
  122.     ;; CODING-SYSTEM is no-conversion or undecided.
  123.     (error "Can't prefer the coding system `%s'" coding-system))
  124.     (set coding-category (or parent coding-system))
  125.     (if (not (eq coding-category (car coding-category-list)))
  126.     ;; We must change the order.
  127.     (setq coding-category-list
  128.           (cons coding-category
  129.             (delq coding-category coding-category-list))))
  130.     (if (and parent (interactive-p))
  131.     (message "Highest priority is set to %s (parent of %s)"
  132.          parent coding-system))
  133.     (set-default-coding-systems (or parent coding-system))))
  134.  
  135.  
  136. ;;; Language support staffs.
  137.  
  138. (defvar language-info-alist nil
  139.   "Alist of language names vs the corresponding information of various kind.
  140. Each element looks like:
  141.     (LANGUAGE-NAME . ((KEY . INFO) ...))
  142. where LANGUAGE-NAME is a string,
  143. KEY is a symbol denoting the kind of information,
  144. INFO is any Lisp object which contains the actual information related
  145. to KEY.")
  146.  
  147. (defun get-language-info (language-name key)
  148.   "Return the information for LANGUAGE-NAME of the kind KEY.
  149. KEY is a symbol denoting the kind of required information."
  150.   (if (symbolp language-name)
  151.       (setq language-name (symbol-name language-name)))
  152.   (let ((lang-slot (assoc-ignore-case language-name language-info-alist)))
  153.     (if lang-slot
  154.     (cdr (assq key (cdr lang-slot))))))
  155.  
  156. (defun mule-frob-after-load-hack (string)
  157.   (if (> emacs-minor-version 4)
  158.       (concat string ".elc")
  159.     string))
  160.  
  161. (defun set-language-info (language-name key info)
  162.   "Set for LANGUAGE-NAME the information INFO under KEY.
  163. KEY is a symbol denoting the kind of information.
  164. INFO is any Lisp object which contains the actual information.
  165.  
  166. Currently, the following KEYs are used by Emacs:
  167.  
  168. charset: list of symbols whose values are charsets specific to the language.
  169.  
  170. coding-system: list of coding systems specific to the langauge.
  171.  
  172. tutorial: a tutorial file name written in the language.
  173.  
  174. sample-text: one line short text containing characters of the language.
  175.  
  176. documentation: t or a string describing how Emacs supports the language.
  177.       If a string is specified, it is shown before any other information
  178.       of the language by the command `describe-language-environment'.
  179.  
  180. setup-function: a function to call for setting up environment
  181.        convenient for a user of the language.
  182.  
  183. If KEY is documentation or setup-function, you can also specify
  184. a cons cell as INFO, in which case, the car part should be
  185. a normal value as INFO for KEY (as described above),
  186. and the cdr part should be a symbol whose value is a menu keymap
  187. in which an entry for the language is defined.  But, only the car part
  188. is actually set as the information.
  189.  
  190. We will define more KEYs in the future.  To avoid conflict,
  191. if you want to use your own KEY values, make them start with `user-'."
  192.   (if (symbolp language-name)
  193.       (setq language-name (symbol-name language-name)))
  194.   (let (lang-slot key-slot)
  195.     (setq lang-slot (assoc language-name language-info-alist))
  196.     (if (null lang-slot)        ; If no slot for the language, add it.
  197.     (setq lang-slot (list language-name)
  198.           language-info-alist (cons lang-slot language-info-alist)))
  199.     (setq key-slot (assq key lang-slot))
  200.     (if (null key-slot)            ; If no slot for the key, add it.
  201.     (progn
  202.       (setq key-slot (list key))
  203.       (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
  204.     ;; Setup menu.
  205.     (cond ((eq key 'documentation)
  206.            ;; (define-key-after
  207.            ;;   (if (consp info)
  208.            ;;       (prog1 (symbol-value (cdr info))
  209.            ;;         (setq info (car info)))
  210.            ;;     describe-language-environment-map)
  211.            ;;   (vector (intern language-name))
  212.            ;;   (cons language-name 'describe-specified-language-support)
  213.            ;;   t)
  214.        (if (consp info)
  215.            (setq info (car info)))
  216.        (when (featurep 'menubar)
  217.          (eval-after-load
  218.           (mule-frob-after-load-hack "x-menubar")
  219.           `(add-menu-button
  220.         '("Mule" "Describe Language Support")
  221.         (vector ,language-name
  222.             '(describe-language-environment ,language-name)
  223.             t))))
  224.        )
  225.       ((eq key 'setup-function)
  226.            ;; (define-key-after
  227.            ;;   (if (consp info)
  228.            ;;       (prog1 (symbol-value (cdr info))
  229.            ;;         (setq info (car info)))
  230.            ;;     setup-language-environment-map)
  231.            ;;   (vector (intern language-name))
  232.            ;;   (cons language-name 'setup-specified-language-environment)
  233.            ;;   t)
  234.        (if (consp info)
  235.            (setq info (car info)))
  236.        (when (featurep 'menubar)
  237.          (eval-after-load
  238.           (mule-frob-after-load-hack "x-menubar")
  239.           `(add-menu-button
  240.         '("Mule" "Set Language Environment")
  241.         (vector ,language-name
  242.             '(set-language-environment ,language-name)
  243.             t))))
  244.            ))
  245.  
  246.     (setcdr key-slot info)
  247.     ))
  248.  
  249. (defun set-language-info-alist (language-name alist)
  250.   "Set for LANGUAGE-NAME the information in ALIST.
  251. ALIST is an alist of KEY and INFO.  See the documentation of
  252. `set-langauge-info' for the meanings of KEY and INFO."
  253.   (if (symbolp language-name)
  254.       (setq language-name (symbol-name language-name)))
  255.   (while alist
  256.     (set-language-info language-name (car (car alist)) (cdr (car alist)))
  257.     (setq alist (cdr alist))))
  258.  
  259. (defun read-language-name (key prompt &optional default)
  260.   "Read language name which has information for KEY, prompting with PROMPT.
  261. DEFAULT is the default choice of language.
  262. This returns a language name as a string."
  263.   (let* ((completion-ignore-case t)
  264.      (name (completing-read prompt
  265.                 language-info-alist
  266.                 (function (lambda (elm) (assq key elm)))
  267.                 t nil default)))
  268.     (if (and (> (length name) 0)
  269.          (get-language-info name key))
  270.     name)))
  271.  
  272. ;;; Multilingual input methods.
  273.  
  274. (defconst leim-list-file-name "leim-list.el"
  275.   "Name of LEIM list file.
  276. This file contains a list of libraries of Emacs input methods (LEIM)
  277. in the format of Lisp expression for registering each input method.
  278. Emacs loads this file at startup time.")
  279.  
  280. (defvar leim-list-header (format "\
  281. ;;; %s -- list of LEIM (Library of Emacs Input Method)
  282. ;;
  283. ;; This file contains a list of LEIM (Library of Emacs Input Method)
  284. ;; in the same directory as this file.  Loading this file registeres
  285. ;; the whole input methods in Emacs.
  286. ;;
  287. ;; Each entry has the form:
  288. ;;   (register-input-method
  289. ;;    INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
  290. ;;    TITLE DESCRIPTION
  291. ;;    ARG ...)
  292. ;; See the function `register-input-method' for the meanings of arguments.
  293. ;;
  294. ;; If this directory is included in load-path, Emacs automatically
  295. ;; loads this file at startup time.
  296.  
  297. "
  298.                  leim-list-file-name)
  299.   "Header to be inserted in LEIM list file.")
  300.  
  301. (defvar leim-list-entry-regexp "^(register-input-method"
  302.   "Regexp matching head of each entry in LEIM list file.
  303. See also the variable `leim-list-header'")
  304.  
  305. (defvar update-leim-list-functions
  306.   '(quail-update-leim-list-file)
  307.   "List of functions to call to update LEIM list file.
  308. Each function is called with one arg, LEIM directory name.")
  309.  
  310. (defun update-leim-list-file (&rest dirs)
  311.   "Update LEIM list file in directories DIRS."
  312.   (let ((functions update-leim-list-functions))
  313.     (while functions
  314.       (apply (car functions) dirs)
  315.       (setq functions (cdr functions)))))
  316.  
  317. (defvar current-input-method nil
  318.   "The current input method for multilingual text.
  319. If nil, that means no input method is activated now.")
  320. (make-variable-buffer-local 'current-input-method)
  321. (put 'current-input-method 'permanent-local t)
  322.  
  323. (defvar current-input-method-title nil
  324.   "Title string of the current input method shown in mode line.")
  325. (make-variable-buffer-local 'current-input-method-title)
  326. (put 'current-input-method-title 'permanent-local t)
  327.  
  328. (defcustom default-input-method nil
  329.   "*Default input method for multilingual text.
  330. This is the input method activated automatically by the command
  331. `toggle-input-method' (\\[toggle-input-method])."
  332.   :group 'mule)
  333.  
  334. (defvar input-method-history nil
  335.   "History list for some commands that read input methods.")
  336. (make-variable-buffer-local 'input-method-history)
  337. (put 'input-method-history 'permanent-local t)
  338.  
  339. (defvar inactivate-current-input-method-function nil
  340.   "Function to call for inactivating the current input method.
  341. Every input method should set this to an appropriate value when activated.
  342. This function is called with no argument.
  343.  
  344. This function should never change the value of `current-input-method'.
  345. It is set to nil by the function `inactivate-input-method'.")
  346. (make-variable-buffer-local 'inactivate-current-input-method-function)
  347. (put 'inactivate-current-input-method-function 'permanent-local t)
  348.  
  349. (defvar describe-current-input-method-function nil
  350.   "Function to call for describing the current input method.
  351. This function is called with no argument.")
  352. (make-variable-buffer-local 'describe-current-input-method-function)
  353. (put 'describe-current-input-method-function 'permanent-local t)
  354.  
  355. (defvar input-method-alist nil
  356.   "Alist of input method names vs the corresponding information to use it.
  357. Each element has the form:
  358.     (INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC TITLE DESCRIPTION ...)
  359. See the function `register-input-method' for the meanings of each elements.")
  360.  
  361. (defun register-input-method (input-method language-name &rest args)
  362.   "Register INPUT-METHOD as an input method for LANGUAGE-NAME.
  363. INPUT-METHOD and LANGUAGE-NAME are symbols or strings.
  364. The remaining arguments are:
  365.     ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARG ...
  366.  where,
  367. ACTIVATE-FUNC is a function to call for activating this method.
  368. TITLE is a string shown in mode-line while this method is active,
  369. DESCRIPTION is a string describing about this method,
  370. Arguments to ACTIVATE-FUNC are INPUT-METHOD and ARGs."
  371.   (if (symbolp language-name)
  372.       (setq language-name (symbol-name language-name)))
  373.   (if (symbolp input-method)
  374.       (setq input-method (symbol-name input-method)))
  375.   (let ((info (cons language-name args))
  376.     (slot (assoc input-method input-method-alist)))
  377.     (if slot
  378.     (setcdr slot info)
  379.       (setq slot (cons input-method info))
  380.       (setq input-method-alist (cons slot input-method-alist)))))
  381.  
  382. (defun read-input-method-name (prompt &optional default inhibit-null)
  383.   "Read a name of input method from a minibuffer prompting with PROMPT.
  384. If DEFAULT is non-nil, use that as the default,
  385.   and substitute it into PROMPT at the first `%s'.
  386. If INHIBIT-NULL is non-nil, null input signals an error.
  387.  
  388. The return value is a string."
  389.   (if default
  390.       (setq prompt (format prompt default)))
  391.   (let* ((completion-ignore-case t)
  392.      ;; This binding is necessary because input-method-history is
  393.      ;; buffer local.
  394.      (input-method (completing-read prompt input-method-alist
  395.                     nil t nil 'input-method-history)
  396.                ;;default)
  397.                ))
  398.     (if (> (length input-method) 0)
  399.     input-method
  400.       (if inhibit-null
  401.       (error "No valid input method is specified")))))
  402.  
  403. (defun activate-input-method (input-method)
  404.   "Turn INPUT-METHOD on.
  405. If some input method is already on, turn it off at first."
  406.   (if (symbolp input-method)
  407.       (setq input-method (symbol-name input-method)))
  408.   (if (and current-input-method
  409.        (not (string= current-input-method input-method)))
  410.     (inactivate-input-method))
  411.   (unless current-input-method
  412.     (let ((slot (assoc input-method input-method-alist)))
  413.       (if (null slot)
  414.       (error "Can't activate input method `%s'" input-method))
  415.       (apply (nth 2 slot) input-method (nthcdr 5 slot))
  416.       (setq current-input-method input-method)
  417.       (setq current-input-method-title (nth 3 slot))
  418.       (run-hooks 'input-method-activate-hook))))
  419.  
  420. (defun inactivate-input-method ()
  421.   "Turn off the current input method."
  422.   (when current-input-method
  423.     (if input-method-history
  424.     (unless (string= current-input-method (car input-method-history))
  425.       (setq input-method-history
  426.         (cons current-input-method
  427.               (delete current-input-method input-method-history))))
  428.       (setq input-method-history (list current-input-method)))
  429.     (unwind-protect
  430.     (funcall inactivate-current-input-method-function)
  431.       (unwind-protect
  432.       (run-hooks 'input-method-inactivate-hook)
  433.     (setq current-input-method nil
  434.           current-input-method-title nil)))))
  435.  
  436. (defun select-input-method (input-method)
  437.   "Select and turn on INPUT-METHOD.
  438. This sets the default input method to what you specify,
  439. and turn it on for the current buffer."
  440.   (interactive
  441.    (let* ((default (or (car input-method-history) default-input-method)))
  442.      (list (read-input-method-name
  443.         (if default "Select input method (default %s): " "Select input method: ")
  444.         default t))))
  445.   (activate-input-method input-method)
  446.   (setq default-input-method input-method))
  447.  
  448. (defun toggle-input-method (&optional arg)
  449.   "Turn on or off a multilingual text input method for the current buffer.
  450.  
  451. With arg, read an input method from minibuffer and turn it on.
  452.  
  453. Without arg, if some input method is currently activated, turn it off,
  454. else turn on an input method selected last time
  455. or the default input method (see `default-input-method').
  456.  
  457. When there's no input method to turn on, turn on what read from minibuffer."
  458.   (interactive "P")
  459.   (let* ((default (or (car input-method-history) default-input-method)))
  460.     (if (and current-input-method (not arg))
  461.     (inactivate-input-method)
  462.       (activate-input-method
  463.        (if (or arg (not default))
  464.        (read-input-method-name
  465.         (if default "Input method (default %s): " "Input method: " )
  466.         default t)  
  467.      default))
  468.       (or default-input-method
  469.       (setq default-input-method current-input-method)))))
  470.  
  471. (defun describe-input-method (input-method)
  472.   "Describe  input method INPUT-METHOD."
  473.   (interactive
  474.    (list (read-input-method-name
  475.       "Describe input method (default, current choice): ")))
  476.   (if (and input-method (symbolp input-method))
  477.       (setq input-method (symbol-name input-method)))
  478.   (if (null input-method)
  479.       (describe-current-input-method)
  480.     (with-output-to-temp-buffer "*Help*"
  481.       (let ((elt (assoc input-method input-method-alist)))
  482.     (princ (format "Input method: %s (`%s' in mode line) for %s\n  %s\n"
  483.                input-method (nth 3 elt) (nth 1 elt) (nth 4 elt)))))))
  484.  
  485. (defun describe-current-input-method ()
  486.   "Describe the input method currently in use."
  487.   (if current-input-method
  488.       (if (and (symbolp describe-current-input-method-function)
  489.            (fboundp describe-current-input-method-function))
  490.       (funcall describe-current-input-method-function)
  491.     (message "No way to describe the current input method `%s'"
  492.          (cdr current-input-method))
  493.     (ding))
  494.     (error "No input method is activated now")))
  495.  
  496. (defun read-multilingual-string (prompt &optional initial-input
  497.                     input-method)
  498.   "Read a multilingual string from minibuffer, prompting with string PROMPT.
  499. The input method selected last time is activated in minibuffer.
  500. If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
  501. initially.
  502. Optional 3rd argument INPUT-METHOD specifies the input method
  503. to be activated instead of the one selected last time.  It is a symbol
  504. or a string."
  505.   (setq input-method
  506.     (or input-method
  507.         default-input-method
  508.         (read-input-method-name "Input method: " nil t)))
  509.   (if (and input-method (symbolp input-method))
  510.       (setq input-method (symbol-name input-method)))
  511.   (let ((current-input-method input-method))
  512.     ;; FSFmacs
  513.     ;; (read-string prompt initial-input nil nil t)))
  514.     (read-string prompt initial-input nil)))
  515.  
  516. ;; Variables to control behavior of input methods.  All input methods
  517. ;; should react to these variables.
  518.  
  519. (defcustom input-method-verbose-flag t
  520.   "*If this flag is non-nil, input methods give extra guidance.
  521.  
  522. The extra guidance is done by showing list of available keys in echo
  523. area.
  524.  
  525. For complex input methods such as `chinese-py' and `japanese',
  526. when you use the input method in the minibuffer, the guidance is
  527. shown at the bottom short window (split from the existing window).
  528. For simple input methods, guidance is not shown
  529. when you are in the minibuffer."
  530.   :type 'boolean
  531.   :group 'mule)
  532.  
  533. (defcustom input-method-highlight-flag t
  534.   "*If this flag is non-nil, input methods highlight partially-entered text.
  535. For instance, while you are in the middle of a Quail input method sequence,
  536. the text inserted so far is temporarily underlined.
  537. The underlining goes away when you finish or abort the input method sequence."
  538.   :type 'boolean
  539.   :group 'mule)
  540.  
  541. (defvar input-method-activate-hook nil
  542.   "Normal hook run just after an input method is activated.
  543.  
  544. The variable `current-input-method' keeps the input method name
  545. just activated.")
  546.  
  547. (defvar input-method-inactivate-hook nil
  548.   "Normal hook run just after an input method is inactivated.
  549.  
  550. The variable `current-input-method' still keeps the input method name
  551. just inacitvated.")
  552.  
  553. (defvar input-method-after-insert-chunk-hook nil
  554.   "Normal hook run just after an input method insert some chunk of text.")
  555.  
  556. (defvar input-method-exit-on-invalid-key nil
  557.   "This flag controls the behaviour of an input method on invalid key input.
  558. Usually, when a user types a key which doesn't start any character
  559. handled by the input method, the key is handled by turning off the
  560. input method temporalily.  After the key is handled, the input method is 
  561. back on.
  562. But, if this flag is non-nil, the input method is never back on.")
  563.  
  564.  
  565. (defun setup-specified-language-environment ()
  566.   "Set up multi-lingual environment convenient for the specified language."
  567.   (interactive)
  568.   (let (language-name)
  569.     (if (and (symbolp last-command-event)
  570.          (or (not (eq last-command-event 'Default))
  571.          (setq last-command-event 'English))
  572.          (setq language-name (symbol-name last-command-event)))
  573.     (set-language-environment language-name)
  574.       (error "Bogus calling sequence"))))
  575.  
  576. (defvar current-language-environment "English"
  577.   "The last language environment specified with `set-language-environment'.")
  578.  
  579. (defun set-language-environment (language-name)
  580.   "Set up multi-lingual environment for using LANGUAGE-NAME.
  581. This sets the coding system priority and the default input method
  582. and sometimes other things."
  583.   (interactive (list (read-language-name 'setup-function
  584.                      "Set language environment: ")))
  585.   (if language-name
  586.       (if (symbolp language-name)
  587.       (setq language-name (symbol-name language-name)))
  588.     (setq language-name "English"))
  589.   (if (null (get-language-info language-name 'setup-function))
  590.       (error "Language environment not defined: %S" language-name))
  591.   (funcall (get-language-info language-name 'setup-function))
  592.   (setq current-language-environment language-name)
  593.   (force-mode-line-update t))
  594.  
  595. ;; Print all arguments with `princ', then print "\n".
  596. (defsubst princ-list (&rest args)
  597.   (while args (princ (car args)) (setq args (cdr args)))
  598.   (princ "\n"))
  599.  
  600. ;; Print a language specific information such as input methods,
  601. ;; charsets, and coding systems.  This function is intended to be
  602. ;; called from the menu:
  603. ;;   [menu-bar mule describe-language-environment LANGUAGE]
  604. ;; and should not run it by `M-x describe-current-input-method-function'.
  605. (defun describe-specified-language-support ()
  606.   "Describe how Emacs supports the specified language environment."
  607.   (interactive)
  608.   (let (language-name)
  609.     (if (not (and (symbolp last-command-event)
  610.           (setq language-name (symbol-name last-command-event))))
  611.     (error "Bogus calling sequence"))
  612.     (describe-language-environment language-name)))
  613.  
  614. (defun describe-language-environment (language-name)
  615.   "Describe how Emacs supports language environment LANGUAGE-NAME."
  616.   (interactive
  617.    (list (read-language-name
  618.       'documentation
  619.       "Describe language environment (default, current choise): ")))
  620.   (if (null language-name)
  621.       (setq language-name current-language-environment))
  622.   (if (or (null language-name)
  623.       (null (get-language-info language-name 'documentation)))
  624.       (error "No documentation for the specified language"))
  625.   (if (symbolp language-name)
  626.       (setq language-name (symbol-name language-name)))
  627.   (let ((doc (get-language-info language-name 'documentation)))
  628.     (with-output-to-temp-buffer "*Help*"
  629.       (if (stringp doc)
  630.       (progn
  631.         (princ-list doc)
  632.         (terpri)))
  633.       (let ((str (get-language-info language-name 'sample-text)))
  634.     (if (stringp str)
  635.         (progn
  636.           (princ "Sample text:\n")
  637.           (princ-list "  " str)
  638.           (terpri))))
  639.       (princ "Input methods:\n")
  640.       (let ((l input-method-alist))
  641.     (while l
  642.       (if (string= language-name (nth 1 (car l)))
  643.           (princ-list "  " (car (car l))
  644.               (format " (`%s' in mode line)" (nth 3 (car l)))))
  645.       (setq l (cdr l))))
  646.       (terpri)
  647.       (princ "Character sets:\n")
  648.       (let ((l (get-language-info language-name 'charset)))
  649.     (if (null l)
  650.         (princ-list "  nothing specific to " language-name)
  651.       (while l
  652.         (princ-list "  " (car l) ": "
  653.             (charset-description (car l)))
  654.         (setq l (cdr l)))))
  655.       (terpri)
  656.       (princ "Coding systems:\n")
  657.       (let ((l (get-language-info language-name 'coding-system)))
  658.     (if (null l)
  659.         (princ-list "  nothing specific to " language-name)
  660.       (while l
  661.         (princ ; (format "  %s (`%c' in mode line):\n\t%s\n"
  662.          ;; In XEmacs, `coding-system-mnemonic' returns string.
  663.          (format "  %s (`%s' in mode line):\n\t%s\n"
  664.              (car l)
  665.              (coding-system-mnemonic (car l))
  666.              (coding-system-doc-string (car l))))
  667.         (setq l (cdr l))))))))
  668.  
  669. ;;; Charset property
  670.  
  671. ;; (defsubst get-charset-property (charset propname)
  672. ;;   "Return the value of CHARSET's PROPNAME property.
  673. ;; This is the last value stored with
  674. ;; `(put-charset-property CHARSET PROPNAME VALUE)'."
  675. ;;   (plist-get (charset-plist charset) propname))
  676.  
  677. ;; (defsubst put-charset-property (charset propname value)
  678. ;;   "Store CHARSETS's PROPNAME property with value VALUE.
  679. ;; It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
  680. ;;   (set-charset-plist charset
  681. ;;                      (plist-put (charset-plist charset) propname value)))
  682.  
  683. (defvar char-code-property-table
  684.   (make-char-table 'generic)
  685.   "Char-table containing a property list of each character code.
  686. ;; 
  687. See also the documentation of `get-char-code-property' and
  688. `put-char-code-property'")
  689. ;;   (let ((plist (aref char-code-property-table char)))
  690. (defun get-char-code-property (char propname)
  691.   "Return the value of CHAR's PROPNAME property in `char-code-property-table'."
  692.   (let ((plist (get-char-table char char-code-property-table)))
  693.     (if (listp plist)
  694.     (car (cdr (memq propname plist))))))
  695.  
  696. (defun put-char-code-property (char propname value)
  697.   "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'.
  698. It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
  699.   (let ((plist (get-char-table char char-code-property-table)))
  700.     (if plist
  701.     (let ((slot (memq propname plist)))
  702.       (if slot
  703.           (setcar (cdr slot) value)
  704.         (nconc plist (list propname value))))
  705.       (put-char-table char (list propname value) char-code-property-table)
  706.       )))
  707. ;;               (setcar (cdr slot) value)
  708. ;;             (nconc plist (list propname value))))
  709. ;;       (aset char-code-property-table char (list propname value)))))
  710.  
  711. ;;; mule-cmds.el ends here
  712.